// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import Vuex from 'vuex'
import App from './App'
import router from './router'
import http from './assets/js/http'
import VueRouter from 'vue-router'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import './assets/css/base.css'
import './assets/css/common.css'
import 'font-awesome/css/font-awesome.css'
import './assets/color.scss'
import './assets/index.scss'
import 'babel-polyfill'


// ajax this.$http.post/get(url, params).then(response => {console.log(response)})
Vue.use(http)
Vue.use(VueRouter)
// vuex
Vue.use(Vuex)
Vue.use(ElementUI)


Vue.config.productionTip = false

// const router = new VueRouter({// 创建 router 实例，然后传 routes配置
//   routes//routes: routes
// })
//全局前置守卫
router.beforeEach((to, from, next) => {//即将要进入的目标 [路由对象],当前导航正要离开的路由,一定要调用该方法来 resolve 这个钩子
	/*
	 确保要调用 next方法，否则钩子就不会被 resolved。
	 导航在所有守卫 resolve 完之前一直处于 等待中
	 * */
  //NProgress.start();
  if (to.path == '/login') {//即将进入login
    sessionStorage.removeItem('user');
  }
  let user = JSON.parse(sessionStorage.getItem('user'));
  if (!user && to.path != '/login') {
    next({ path: '/login' })
  } else {
    next()
  }
})


/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
